﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace Web_HengliSeed
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application["StartTime"] = System.DateTime.Now; 
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (Common.CheckMes.CheckKeyWord(Request.QueryString[i].ToString()))
                {
                    BLL.SysLog.AddSysLog("【" + Request.Url.AbsolutePath + "】Url含有特殊字符！", 0);
                    Common.CheckMes.showHtmlMsg(ClassFile.Function.ReadFiles(Server.MapPath("Error.html")));
                }
            }
        }

        protected void Application_EndRequest(Object sender, EventArgs e)
        {
            System.DateTime startTime = (System.DateTime)Application["StartTime"];
            System.DateTime endTime = System.DateTime.Now;
            System.TimeSpan ts = endTime - startTime;

            Application["runtime"] = (Convert.ToDouble((ts.Milliseconds)) / 1000);
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            //Exception objErr = Server.GetLastError().GetBaseException();
            //Server.ClearError();
            //try
            //{
            //    BLL.SysLog.AddSysLog("【" + Request.Url.AbsolutePath + "】" + Server.HtmlEncode(objErr.Message), 0);
            //}
            //catch (Exception ex)
            //{
            //    Common.FileMes.WriteFile(Server.MapPath("~/ErrorLog/log.log"), "\n\t【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】\n\t【错误1】" + objErr.Message + "\n\t【错误2】" + ex.Message);
            //}
            //Common.CheckMes.showHtmlMsg(ClassFile.Function.ReadFiles(Server.MapPath("Error.html")));
        }
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}